package util;

import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class LogUtil {
    private static final String LOG_FILE_PATH = "log.txt";

    public static void log(String logLevel, String message, String operator) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String logContent = sdf.format(new Date()) + " [" + logLevel + "] " + message + " 操作人：" + operator + "\n";
        try (FileWriter fw = new FileWriter(LOG_FILE_PATH, true)) {
            fw.write(logContent);
            fw.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}